package isjinhao.jlox.grammar.code.visitor;

import isjinhao.jlox.grammar.code.represention.*;
import isjinhao.jlox.grammar.statement.represention.Statement;

import java.util.List;

/**
 * @Author ISJINHAO
 * @Date 2021/2/28 20:46
 */
public class CodePrintVisitor implements CodeVisitor<String> {

    @Override
    public String visitIfCode(IfCode ifCode) {

        StringBuilder toString = new StringBuilder();

        toString.append("if (");

        toString.append(ifCode.getIfCondition().toString());

        toString.append(") \n");
        toString.append(ifCode.getIfStatement().toString());

        for(IfCode.ElseIfCode item : ifCode.getElseIfList()) {

        }

        return null;
    }

    @Override
    public String visitWhileCode(WhileCode whileCode) {
        return null;
    }

    @Override
    public String visitForCode(ForCode forCode) {
        return null;
    }

    @Override
    public String visitDoWhileCode(DoWhileCode doWhileCode) {
        return null;
    }

    @Override
    public String visitStatementCode(StatementCode statementCode) {
        return null;
    }


    @Override
    public String visitBlockStmt(Block block) {
        String blankStr = blankStr();
        StringBuffer toString = new StringBuffer();
        toString.append(blankStr + "{");
        length++;
        List<Statement> statements = block.getStatements();
        for (Statement statement : statements) {
            String accept = statement.accept(this);
            toString.append("\n" + accept);
        }
        length--;
        toString.append("\n" + blankStr + "}");
        return toString.toString();
    }
}
